import 'package:finance_app/src/entities/cpf_contribution_entity.dart';
import 'package:finance_app/src/entities/transaction_entity.dart';

cpfContributionEntityFromJson(CpfContributionEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['number'] != null) {
		data.number = json['number'].toString();
	}
	if (json['payments'] != null) {
		data.payments = (json['payments'] as List).map((v) => TransactionEntity().fromJson(v)).toList();
	}
	if (json['payment_type_id'] != null) {
		data.paymentTypeID = json['payment_type_id'] is String
				? int.tryParse(json['payment_type_id'])
				: json['payment_type_id'].toInt();
	}
	if (json['paid_at'] != null) {
		data.paidAt = json['paid_at'].toString();
	}
	if (json['employee_cpf'] != null) {
		data.employeeCpf = json['employee_cpf'] is String
				? num.tryParse(json['employee_cpf'])
				: json['employee_cpf'];
	}
	if (json['employer_cpf'] != null) {
		data.employerCpf = json['employer_cpf'] is String
				? num.tryParse(json['employer_cpf'])
				: json['employer_cpf'];
	}
	if (json['cpf_overdue_interest'] != null) {
		data.cpfOverdueInterest = json['cpf_overdue_interest'] is String
				? num.tryParse(json['cpf_overdue_interest'])
				: json['cpf_overdue_interest'];
	}
	if (json['fwl'] != null) {
		data.fwl = json['fwl'] is String
				? num.tryParse(json['fwl'])
				: json['fwl'];
	}
	if (json['fwl_overdue_interest'] != null) {
		data.fwlOverdueInterest = json['fwl_overdue_interest'] is String
				? num.tryParse(json['fwl_overdue_interest'])
				: json['fwl_overdue_interest'];
	}
	if (json['sdl'] != null) {
		data.sdl = json['sdl'] is String
				? num.tryParse(json['sdl'])
				: json['sdl'];
	}
	if (json['community_donation'] != null) {
		data.communityDonation = json['community_donation'] is String
				? num.tryParse(json['community_donation'])
				: json['community_donation'];
	}
	if (json['community_donation_donors'] != null) {
		data.communityDonationDonors = json['community_donation_donors'] is String
				? int.tryParse(json['community_donation_donors'])
				: json['community_donation_donors'].toInt();
	}
	if (json['mbmf'] != null) {
		data.mbmf = json['mbmf'] is String
				? num.tryParse(json['mbmf'])
				: json['mbmf'];
	}
	if (json['mbmf_donors'] != null) {
		data.mbmfDonors = json['mbmf_donors'] is String
				? int.tryParse(json['mbmf_donors'])
				: json['mbmf_donors'].toInt();
	}
	if (json['sinda'] != null) {
		data.sinda = json['sinda'] is String
				? num.tryParse(json['sinda'])
				: json['sinda'];
	}
	if (json['sinda_donors'] != null) {
		data.sindaDonors = json['sinda_donors'] is String
				? int.tryParse(json['sinda_donors'])
				: json['sinda_donors'].toInt();
	}
	if (json['cdac'] != null) {
		data.cdac = json['cdac'] is String
				? num.tryParse(json['cdac'])
				: json['cdac'];
	}
	if (json['cdac_donors'] != null) {
		data.cdacDonors = json['cdac_donors'] is String
				? int.tryParse(json['cdac_donors'])
				: json['cdac_donors'].toInt();
	}
	if (json['ecf'] != null) {
		data.ecf = json['ecf'] is String
				? num.tryParse(json['ecf'])
				: json['ecf'];
	}
	if (json['ecf_donors'] != null) {
		data.ecfDonors = json['ecf_donors'] is String
				? int.tryParse(json['ecf_donors'])
				: json['ecf_donors'].toInt();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['company_id'] != null) {
		data.companyID = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['start_date'] != null) {
		data.startDate = json['start_date'].toString();
	}
	if (json['end_date'] != null) {
		data.endDate = json['end_date'].toString();
	}
	if (json['month'] != null) {
		data.month = json['month'].toString();
	}
	if (json['year'] != null) {
		data.year = json['year'].toString();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	return data;
}

Map<String, dynamic> cpfContributionEntityToJson(CpfContributionEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['number'] = entity.number;
	data['payments'] =  entity.payments?.map((v) => v.toJson())?.toList();
	data['payment_type_id'] = entity.paymentTypeID;
	data['paid_at'] = entity.paidAt;
	data['employee_cpf'] = entity.employeeCpf;
	data['employer_cpf'] = entity.employerCpf;
	data['cpf_overdue_interest'] = entity.cpfOverdueInterest;
	data['fwl'] = entity.fwl;
	data['fwl_overdue_interest'] = entity.fwlOverdueInterest;
	data['sdl'] = entity.sdl;
	data['community_donation'] = entity.communityDonation;
	data['community_donation_donors'] = entity.communityDonationDonors;
	data['mbmf'] = entity.mbmf;
	data['mbmf_donors'] = entity.mbmfDonors;
	data['sinda'] = entity.sinda;
	data['sinda_donors'] = entity.sindaDonors;
	data['cdac'] = entity.cdac;
	data['cdac_donors'] = entity.cdacDonors;
	data['ecf'] = entity.ecf;
	data['ecf_donors'] = entity.ecfDonors;
	data['status'] = entity.status;
	data['company_id'] = entity.companyID;
	data['start_date'] = entity.startDate;
	data['end_date'] = entity.endDate;
	data['month'] = entity.month;
	data['year'] = entity.year;
	data['total'] = entity.total;
	return data;
}